package be.jprojects.subscription.dataaccess.mysql;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.ResourceBundle;

import be.jprojects.subscription.dataaccess.CityDataAccess;
import be.jprojects.subscription.dataaccess.CountryDataAccess;
import be.jprojects.subscription.dataaccess.DataAccessObjectFactory;
import be.jprojects.subscription.dataaccess.PersonDataAccess;
import be.jprojects.subscription.dataaccess.ProvinceDataAccess;
import be.jprojects.subscription.dataaccess.StreetDataAccess;

public class MySQLDataAccessObjectFactory extends DataAccessObjectFactory {
	
	private ResourceBundle bundle;
	
	public ResourceBundle getBundle() {
		return bundle;
	}
	
	public MySQLDataAccessObjectFactory() throws Exception {
        bundle = ResourceBundle.getBundle("be.jprojects.subscription.dataaccess.mysql.MySQLConstants");
        Class.forName(bundle.getString("driver"));

	}

	public Connection getConnection() throws SQLException {
		return DriverManager.getConnection(
					bundle.getString("connectionstring"),
					bundle.getString("user"),
					bundle.getString("password"));
	}
	
	@Override
	public PersonDataAccess getPersonDataAccess() {
		return new MySQLPersonDataAccess(this);
	}
	
	@Override
	public CityDataAccess getCityDataAccess() {
		return new MySQLGeoDataAccess(this);
	}

	@Override
	public CountryDataAccess getCountryDataAccess() {
		return new MySQLGeoDataAccess(this);
	}

	@Override
	public ProvinceDataAccess getProvinceDataAccess() {
		return new MySQLGeoDataAccess(this);
	}

	@Override
	public StreetDataAccess getStreetDataAccess() {
		return new MySQLGeoDataAccess(this);
	}
	

}
